package com.leetcode.LC;

import java.util.Stack;

public class LC1614 {
    public int maxDepth(String s) {

        Stack<Character> stack = new Stack<>();
        int max=0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i)=='('){
                stack.push(s.charAt(i));
                max=Math.max(max,stack.size());
            }else if (s.charAt(i)==')'){
                stack.pop();
            }
        }
        return max;
    }
    public int maxDepth2(String s) {

        int max=0,count=0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i)=='('){
                count++;
                max=Math.max(max,count);
            }else if (s.charAt(i)==')'){
                count--;
            }
        }
        return max;
    }
}
